#!/bin/bash

# MCP服务器启动脚本

echo "🔧 启动MCP服务器..."

# 检查Go环境
if ! command -v go &> /dev/null; then
    echo "❌ Go未安装，请先安装Go 1.21+"
    exit 1
fi

# 安装依赖
echo "📦 检查依赖..."
go mod tidy

# 编译MCP服务器
echo "🔨 编译MCP服务器..."
if ! go build -o mcpserver/mcpserver mcpserver/main.go; then
    echo "❌ 编译失败"
    exit 1
fi

echo "✅ MCP服务器编译成功"
echo "🔧 提供工具:"
echo "   - get_time: 时间查询工具"
echo "   - calculate: 数学计算工具"
echo ""
echo "📝 使用方法:"
echo "   发送JSON-RPC 2.0格式的请求到标准输入"
echo "   示例: echo '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\"}' | ./mcpserver/mcpserver"
echo ""
echo "🛑 按 Ctrl+C 停止服务器"
echo "----------------------------------------"

./mcpserver/mcpserver
